//---------------------------------------------------------------------------
#pragma hdrstop
#include "stdafx.h"
#include "GA.h"

//---------------------------------------------------------------------------
#pragma package(smart_init)
void GA_Class::Process(bool Show, int Chord1, int Chord2, int Chord3, int Chord4)
{
	//FormLearning->GASeries->Clear();
	this->Swarm.Initial();
	this->Swarm.SetChord(Chord1, Chord2, Chord3, Chord4);

	for(int Epoch=0; Epoch<MaxEpoch; Epoch++)
	{
		this->Swarm.Crossover();
		this->Swarm.Mutation(false, Epoch);
		this->Swarm.GetFitness();
		this->Swarm.Survive();

		if(Show)
		{
			//FormLearning->GASeries->AddXY(Epoch, this->Swarm.G_Best[0].Fitness);
			this->Swarm.FitnessRecord[Epoch] += this->Swarm.G_Best[0].Fitness;
		}
	}

	if(Show)
	{
		//paint_Bar(true);
		paint_Particle(this->Swarm.G_Best[0], FormLearning->GAImg, FormLearning->GASeries->Color);
		FormLearning->GALabel->Caption = "GA Fitness: " + IntToStr((int)this->Swarm.G_Best[0].Fitness);
	}
}
